#include "crc.h"



#define POLY1	0x00600340UL
#define POLY2	0x00F0D50BUL
//#define POLY1	0xD8000000UL
//#define POLY2	0x00000000UL
//#define POLY1	0x00000000UL
//#define POLY2	0x0000001BUL

t_digest v_CrcXor[256];
t_digest* CrcXor = v_CrcXor;


bool init_crc_hash()
{
	for (int i = 0; i < 256; ++i)
	{
		int j;
		int v = i;
		t_digest hv;
		hv.digest[0] = 0;
		hv.digest[1] = 0;

		for (j = 0; j < 8; ++j, (v <<= 1))
		{
			hv.digest[0] <<= 1;
			if (hv.digest[1] & 0x80000000UL)
				hv.digest[0] |= 1;
			hv.digest[1] = (hv.digest[1] << 1);
			if (v & 0x80)
			{
				hv.digest[0] ^= POLY1;
				hv.digest[1] ^= POLY2;
			}
		}
		CrcXor[i] = hv;
	}
	return true;
}
